package cloud

import (
	"iot-base/common/notify"
	"iot-base/common/types"
)

type taskHandle func(params []byte) ([]byte, error)

var taskCloudAction = map[string]taskHandle{
	"AddTask":              AddCloudTask,
	"DelTask":              DelCloudTask,
	"ModifyTask":           ModifyCloudTask,
	"AddTaskLog":           AddTaskLog,
	"ModifyTaskLog":        ModifyTaskLog,
	"AddTaskLogDetails":    AddTaskLogDetails,
	"ModifyTaskLogDetails": ModifyTaskLogDetails,
}

func SubCloudMsg() {
	notify.CloudSubReportData(func(params *types.ReqRecordData) ([]byte, error) {
		if fun, ok := taskCloudAction[params.ID]; ok {
			return fun(params.Params)
		}
		return nil, notify.ErrActionNotFound
	})
}
